package com.saudidentalapp;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.saudiapp.lazylist.ImageLoader;
import com.saudidentalapp.SpeakerAdapter.ContactInformationListener;
import com.saudidentalapp.datamodels.Exhibitor;

public class ExibitorsAdapter extends ArrayAdapter<Exhibitor>
{

	Context context;
    int layoutResourceId;    
    ArrayList<Exhibitor>data;
    
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    
    ContactInformationListener contactInformationListener;
    
    
	public ExibitorsAdapter(Context context, int resource, List<Exhibitor> arrayList) 
	{
		super(context, resource, arrayList);
		 this.layoutResourceId = resource;
	        this.context = context;
	        this.data = (ArrayList<Exhibitor>) arrayList;
	        
	        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        imageLoader=new ImageLoader(context.getApplicationContext());
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		View row = convertView;
		ExhibitorHolder holder = null;
       
        if(row == null)
        {
           row = inflater.inflate(layoutResourceId, parent, false);
           
            holder = new ExhibitorHolder();
            holder.txtName = (TextView)row.findViewById(R.id.xtxtSpeakerName);
            holder.imgThumb = (ImageView)row.findViewById(R.id.ximgThumb);
            holder.imgContact = (ImageView)row.findViewById(R.id.ximgContact);
            holder.imgEmail = (ImageView)row.findViewById(R.id.ximgEmail);
           
            row.setTag(holder);
        }
        else
        {
            holder = (ExhibitorHolder)row.getTag();
        }
       
        Exhibitor exhibitor = getItem(position);
        holder.txtName.setText(exhibitor.getName());
        imageLoader.DisplayImage(exhibitor.getThumbImage(), holder.imgThumb);
        holder.imgContact.setTag(exhibitor.getContactNo());
        return row;
    }
   
	
	 public void setContactInformationListener(
				ContactInformationListener contactInformationListener) {
			this.contactInformationListener = contactInformationListener;
		}
	    
    static class ExhibitorHolder
    {       
    	ImageView imgThumb;
    	TextView txtName;
    	ImageView imgContact;
    	ImageView imgEmail;
       
    }
}